# -*- coding:utf-8 -*-
"""
日期:2021年05月10日
"""
from abc import ABCMeta,abstractmethod

class Person:
    def __init__(self,name,dayoff):
        self.__name = name
        self.__dayoff = dayoff
        self.__leader = None

    def setLeader(self,leader):
        self.__leader = leader

    def getName(self):
        return  self.__name

    def getDayoff(self):
        return self.__dayoff

    def request(self):
        print("%s请假%d天"%(self.__name,self.__dayoff))
        if(self.__leader is not None):
            self.__leader.handleRequest(self)

class Manager(metaclass=ABCMeta):
    def __init__(self,title):
        self._title = title
        self._nextLeader = None

    def setNextLeader(self,nextLeader):
        self._nextLeader = nextLeader

    def getTitle(self):
        return self._title

    @abstractmethod
    def handleRequest(self,person):
        pass

class Supervisor(Manager):
    def __init__(self,title):
        super().__init__(title)

    def handleRequest(self,person):
        if(person.getDayoff()<=2):
            print("%s同意%s请假%d天"%(self.getTitle(),person.getName(),person.getDayoff()))

        if(self._nextLeader is not None):
            self._nextLeader.handleRequest(person)

class DepartmentManager(Manager):
    def __init__(self,title):
        super().__init__(title)

    def handleRequest(self, person):
        if (person.getDayoff() > 2 and person.getDayoff() < 5):
            print("%s同意%s请假%d天" % (self.getTitle(), person.getName(), person.getDayoff()))

        if (self._nextLeader is not None):
            self._nextLeader.handleRequest(person)

class CEO(Manager):
    def __init__(self,title):
        super().__init__(title)

    def handleRequest(self, person):
        if (person.getDayoff() > 5):
            print("%s同意%s请假%d天" % (self.getTitle(), person.getName(), person.getDayoff()))

        if (self._nextLeader is not None):
            self._nextLeader.handleRequest(person)


def test():
   su = Supervisor("上级主管")
   dm = DepartmentManager("部门经理")
   ceo = CEO("总经理");

   su.setNextLeader(dm)
   dm.setNextLeader(ceo)

   person = Person("AAA",1)
   person.setLeader(su)
   person.request()

   person = Person("BBB", 4)
   person.setLeader(su)
   person.request()

   person = Person("CCC", 7)
   person.setLeader(su)
   person.request()


test()

